<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>镜像站@Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/admin/plugin/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <!--引入 element-ui 的样式，-->
    <link rel="stylesheet" href="/admin/plugin/element-ui/index.css">
    <!-- 必须先引入vue，  后使用element-ui -->
    <script type="text/javascript" src="/admin/js-css/js/vue.min.js"></script>
    <!-- 引入element 的组件库-->
    <script type="text/javascript" src="/admin/plugin/element-ui/index.js"></script>

    <script type="text/javascript" src="/admin/plugin/element-ui/httpVueLoader.js"></script>
	<link rel="stylesheet" href="/admin/js-css/css/backColor.css" media="all">

    <script type="text/javascript" src="/admin/js-css/js/mx1.0.js?v=1.3"></script>
    <style type="text/css">
        .layui-table-click {
            background-color:cadetblue !important;
            color:white;
        }
        .layui-btn+.layui-btn {
            margin-left: 0px;
        }
        .layui-table, .layui-table-view {
             margin: 0px 0;
        }

        /**输入框高度设置**/
        .layui-input, .layui-select, .layui-textarea {
            height: 30px;
            line-height: 30px\9;
        }
        /**按钮样式设置**/
        .layui-btn {
            height: 30px;
            line-height: 30px;
            font-size: 13px;
        }
        .layui-btn+.layui-btn {
            margin-left: 0px;
        }

        .layui-table, .layui-table-view {
            margin: 0px 0;
        }

        button{
            height: 30px;
            line-height: 30px;
            font-size: 13px;
        }
    </style>
    <style type="text/css">
        .layui-table-click {
            background-color:cadetblue !important;
            color:white;
        }

        ::-webkit-scrollbar {
            width: 6px;
            height: 10px;
            background-color: rgba(255, 255, 255, 0.1);
        }

        ::-webkit-scrollbar-thumb {
            background: rgba(144, 147, 153, .3);
            border-radius: 4px;
            cursor: pointer;
        }
        .layui-form-label {
            float: left;
            display: block;
            padding: 7px 1px;
            width: 100px;
            font-weight: 400;
            line-height: 14px;
            text-align: right;
        }

        /**输入框高度设置**/
        .layui-input, .layui-select, .layui-textarea {
            height: 30px;
            line-height: 30px\9;
        }
        /**按钮样式设置**/
        .layui-btn {
            height: 30px;
            line-height: 30px;
            font-size: 13px;
        }
        .layui-btn+.layui-btn {
            margin-left: 0px;
        }

        .layui-table, .layui-table-view {
            margin: 0px 0;
        }

        button{
            height: 30px;
            line-height: 30px;
            font-size: 13px;
        }

        /**列表内容超出自动换行**/
        /*.layui-table-cell {
            height: auto;
            overflow:visible;white-space:normal;text-overflow:clip;
            word-break: break-all;
        }*/
    </style>
</head>
<body>

<div id="app">

    <div class="demoTable" style="padding: 5px;">
        <div class="layui-inline"  style="margin: 3px 0px;">

            <div class="layui-input-inline"  >
                <input class="layui-input" v-model="searchMap.tableId" placeholder="表Id"  autocomplete="off">
            </div>

            <div class="layui-input-inline"  >
                <input class="layui-input" v-model="searchMap.name" placeholder="名称"  autocomplete="off">
            </div>

            <button class="layui-btn" @click="getData" >搜索</button>
        </div>


    </div>

    <div class="layui-btn-group" style="display: none;">
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_add()">增加</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_update()">编辑</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_delete()">删除</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="setRedisInitialValue()">设置自增初始值</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="setbuttons()">设置按钮</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="mobileColumn()">移动</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="interfaceRules()">前端接口授权</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="oneImportPage()">一键导入录入页面</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="copyToOtherItems()">复制到其它项目</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="reloadSystem()">重新装载</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="reloadSystemAll()">装载所有项目</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="expdata()">导出</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="impdata()">导入</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="start_stat()">开启统计</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="WipeDataEvent2()">清空表</button>
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="DeletePhysicalTableEvent2()">删除物理表</button>



    </div>

    <table id="demo" lay-filter="test"></table>

</div>


<script src="/admin/plugin/layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>

    var table = null;
    var $ = null;
    layui.use(['table','jquery'], function(){
        table = layui.table;
        $ = layui.$ //重点处

        //执行渲染
        table.render({
            id:"idTest",
            elem: '#demo' //指定原始表格元素选择器（推荐id选择器）
            ,height: 'full-50' //容器高度
            ,cols:[[{checkbox: true},{field:"id",title:"表Id"},
                {field:"name",title: "栏目名称"}
                ,{field:"parent_name",title: "上级节点名称",minWidth:300}
                ,{field: "class_name",title:"数据接口类名"}
                ,{field: "table_name",title:"表名"}
                ,{field: "pxh",title:"排序号"}]] //设置表头
            ,url:wwwurl+"/admin/api/ColumnManagementController/list"
            ,where:{searchInputDtos:{"paren_id":{key:"paren_id",type:"6",value:top.data.zygl_id}}}
            ,contentType: 'application/json'
            ,method:"post"
            ,page:true
            ,limit:50
            ,toolbar: '.layui-btn-group'
            ,request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            headers: {
                token:localStorage.getItem("token")
            }
            ,parseData:function(res){
                return {
                    "code": "0", //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        //监听行单击事件
        table.on('row(test)', function (obj) {
            //动态添加背景色
            if (obj.tr.hasClass('layui-table-click')) {
                obj.tr.removeClass('layui-table-click');    //删除背景色和
                obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
            } else {
                obj.tr.addClass('layui-table-click');
                obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
            }

            var index = obj.tr.data('index');
            var tableData = table.cache.idTest;//menu 是表格id
            var trHasClass = obj.tr.hasClass('layui-table-click');

            //循环判断class,选中checkbox
            layui.each(tableData, function (i, item) {
                if (trHasClass == true) {
                    if (index == i) {
                        item.LAY_CHECKED = true;
                    }
                } else {
                    if (index == i) {
                        item.LAY_CHECKED = false;
                    }
                }
            });
        });


    });


    var vm = new Vue({
        el:"#app",
        data:{
            searchMap:{}
        },
        methods:{
            getData(){
                let searchInputDtos = {};
                if(vm.searchMap.tableId != undefined && vm.searchMap.tableId != ""){
                    searchInputDtos = {"id":{key:"id",type:"0",value:vm.searchMap.tableId}};
                }else {
                    searchInputDtos = {"name":{key:"name",type:"0",value:vm.searchMap.name}};
                }
                table.reload("idTest", {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {searchInputDtos:searchInputDtos}
                });
            }
        }
    });

    function DeletePhysicalTableEvent2(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        if(ids.length == 0){
            top.error("请选择数据！");
            return ;
        }
        layer.confirm('确定要删除物理表吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/ColumnManagementController/DeletePhysicalTableEvent2", {ids:""+ids},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res);

            })
        }, function (index) {
            //按钮【按钮二】的回调
        });
    }

    function WipeDataEvent2(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        if(ids.length == 0){
            top.error("请选择数据！");
            return ;
        }
        layer.confirm('确定要清空表吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/ColumnManagementController/WipeDataEvent2", {ids:""+ids},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res);

            })
        }, function (index) {
            //按钮【按钮二】的回调
        });
    }

    function impdata(){
        let btn = {btn: ['导入', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                let parms = {};
                let tableNames = [];
                if(data.checksetting.a1){
                    tableNames.push("t_wzfbpt_zygl");
                }
                if(data.checksetting.a2){
                    tableNames.push("t_wzfbpt_config_fbtl_dict");
                }
                if(data.checksetting.a2){
                    tableNames.push("t_wzfbpt_config_fbtl_dict");
                }
                if(data.checksetting.a3){
                    tableNames.push("t_wzfbpt_dict_order");
                    tableNames.push("t_wzfbpt_fbtl_dict_input")
                    tableNames.push("t_wzfbpt_fbtl_dict_list")
                    tableNames.push("t_wzfbpt_fbtl_dict_search")
                }
                if(data.checksetting.a4){
                    tableNames.push("t_wzfbpt_zygl_button");
                }
                if(data.checksetting.a5){
                    tableNames.push("@@_base");
                }
                if(data.checksetting.a6){
                    tableNames.push("t_config_code");
                    tableNames.push("t_config_code_p");
                }
                if(data.checksetting.a7){
                    tableNames.push("t_sys_input");
                    tableNames.push("t_sys_input_group");
                    tableNames.push("t_sys_input_group_column");
                }
                parms["tableNames"] = ""+tableNames;
                parms["excel_path"] = data.xlsPath;
                parms["source_keycode"] = data.source_keycode;
                post("/admin/api/ColumnManagementController/ImportColumnData", parms,function (res) {
                    top.alert(res.msg);
                    win.vm.getProgress();
                });

            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/import_config.html","30%","80%",function () {

        },btn,"导入数据", {});

    }

    function expdata(){
        let btn = {btn: ['导出', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                postBody("/admin/api/ColumnManagementController/ExportColumnData", data,function (res) {
                    win.vm.getProgress();
                });

            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/zyglsTree.html","30%","80%",function () {

        },btn,"导出数据", {});

    }

    function reloadSystemAll(){
        layer.confirm('确定要装载所有项目吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/ColumnManagementController/loadSystemAll", {},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res.msg);

            })
        }, function (index) {
            //按钮【按钮二】的回调
        });
    }

    function reloadSystem(){
        layer.confirm('确定要重新装载吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/ColumnManagementController/loadSystem", {},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res.msg);

            })
        }, function (index) {
            //按钮【按钮二】的回调
        });

    }


    function start_stat(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行开启");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        let i = top.layer.load();
        post("/admin/api/ColumnManagementController/SelectTableToEnableStatisticsEvent2", {ids:""+ids},function (res) {
            top.layer.close(i);
            top.alert(res.msg);
        })
    }

    function oneImportPage(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行授权");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        if(ids.length != 1){
            top.alert("只能选择一条记录进行添加");
            return ;
        }
        var i = top.layer.load();
        post("/admin/api/ColumnManagementController/oneClickImportEntryPage", {zygl_id:""+ids},function (res) {
            top.layer.close(i);
            top.alert(res.msg);
        })
    }

    function copyToOtherItems(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行复制");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        let btn = {btn: ['保存', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                postBody("/admin/api/ColumnManagementController/copyToOtherItems", {selectIds:""+ids,toOrgids:""+data.ids,checksetting:data.checksetting},function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/orgsTree.html","30%","80%",function () {

        },btn,"复制到其它项目", {ids:""+ids});
    }


    function interfaceRules(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行授权");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        if(ids.length != 1){
            top.alert("只能选择一条记录进行授权");
            return ;
        }
        let btn = {btn: ['保存', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                postBody("/admin/api/ColumnManagementController/setRulesInterface", data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/treeRules.html","30%","80%",function () {

        },btn,"前端接口授权", {ids:""+ids});
    }

    function mobileColumn(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行移动");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        let btn = {btn: ['保存', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                post("/admin/api/ColumnManagementController/mobileColumn", {srcIds:""+ids,selectId:""+data},function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/treeMobile.html","30%","80%",function () {

        },btn,"移动栏目", {});
    }

    function setbuttons() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length != 1){
            top.alert("只能选择一条记录进行修改");
            return;
        }
        top.data.uptableId = checkStatus.data[0].id;
        let btn = {btn: ['保存', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                postBody("/admin/api/ColumnManagementController/setTableButtons",data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/setbuttons.html","50%","65%",function () {

        },btn,"设置按钮", {});

    }

    function setRedisInitialValue() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length != 1){
            top.alert("只能选择一条记录进行修改");
            return;
        }
        layer.prompt(function(value, index, elem){
            top.load();
            post("/admin/api/ColumnManagementController/setRedisInitialValue",{zygl_id:checkStatus.data[0].id,value:value},function (res) {
                top.alert(res.msg);
                layer.close(index);
                top.layer.closeAll();
            })

        });
    }


    function f_add() {
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                data.paren_id = top.data.zygl_id;
                postBody("/admin/api/ColumnManagementController/add",data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/columnManagement/input.html?p_zygl_id="+top.data.zygl_id,"50%","60%",function () {

        },btn,"添加栏目",{})
    }

    function f_update() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length != 1){
            top.alert("只能选择一条记录进行修改");
            return;
        }
        post("/admin/api/ColumnManagementController/queryForId",{id:checkStatus.data[0].id},function (res) {
            let btn = {btn: ['确定', '取消']
                ,yes: function(index, layero){
                    console.log(layero);
                    //按钮【按钮一】的回调
                    var win = getTopIframe(layero);
                    var data = win.getData();
                    data.id = checkStatus.data[0].id;
                    var i = top.layer.load();
                    postBody("/admin/api/ColumnManagementController/update",data,function (res) {
                        top.layer.close(i);
                        top.alert(res.msg);
                        table.reload("idTest", {});
                    })
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    //return false 开启该代码可禁止点击该按钮关闭
                }};
            top.f_layer_open_get("/admin/html/columnManagement/input.html?p_zygl_id="+top.data.zygl_id,"50%","60%",function () {

            },btn,"修改栏目",res.data);
        })

    }


    function f_delete() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行删除");
            return;
        }
        var ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        layer.confirm('确定要永久删除吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            load();
            post("/admin/api/ColumnManagementController/delete",{ids:""+ids},function (res) {
                top.alert(res.msg);
                layer.closeAll();
                table.reload("idTest", {});
            })
        }, function (index) {
            //按钮【按钮二】的回调
        });

    }
</script>

</body>
</html>
